<template>
<div>
  <Card>
    <Collapse style="margin-bottom:15px;">
      <Panel>查询
        <div slot="content">
          <Form
            ref="formLkyApplyAdminPass"
            :model="formLkyApplyAdminPass"
            label-position="right"
            :label-width="80"
            inline
          >
            <!--学院、专业、班级查询-->
                       
            <FormItem label="所属学院" prop="name1">
            	<Select v-model="coid" style="width:200px" @on-open-change="onOpenChangeCollege" @on-change="onOpenChangeMajor" clearable >
            		<Option v-for="item in collegeList" :value="item.id" :key="item.id">
            			{{ item.name }}
            		</Option>
            	</Select>
            </FormItem>
            <FormItem label="所属专业" prop="name2">
            	<Select v-model="mid" style="width:200px" @on-change="onOpenFindClassByMid" clearable >
            		<Option v-for="item in majorList" :value="item.id" :key="item.id">
            			{{ item.name }}
            		</Option>
            	</Select>
            </FormItem>
            <FormItem label="所属班级" prop="name3">
            	<Select v-model="cid" style="width:200px" clearable >
            		<Option v-for="item in classList" :value="item.id" :key="item.id" >
            			{{ item.name }}
            		</Option>
            	</Select>
            </FormItem>
            <FormItem>
              <Button type="primary" @click="handleSubmit('formLkyApplyAdminPass')">查询</Button>
              <Button @click="handleReset('formLkyApplyAdminPass')" style="margin-left: 8px">重置</Button>
            </FormItem>
          </Form>
        </div>
      </Panel>
    </Collapse>

    <Table
      ref="tableLkyApplyAdminPass"
      :data="tableData"
      :columns="columns"
      @on-selection-change="onSelectionChange"
      @on-sort-change="onSortChange"
    />
    <div style="margin: 10px;overflow: hidden">
      <div style="float: right;">
        <Page
          :total="total"
          :current="current"
          :page-size="pageSize"
          @on-page-size-change="changePageSize"
          @on-change="changePage"
          :show-total="true"
          show-sizer
        ></Page>
    <Edit v-model="isOpenEditPage"   :LkyApplyAdminPass="editLkyApplyAdminPass"/>
      </div>
    </div>
  </Card>
</div>
</template>
<script>
import { list, batchDelete, listFind } from '@/api/lky/lkyApplyAdminPass'
import { createFormObj } from '@/libs/util'
// 学院查询、专业查询
import { queryAll } from '@/api/lky/lkyCollege'
import { queryAllM } from '@/api/lky/lkyMajor'
import { queryFindClassByMid } from '@/api/lky/lkyClass'
import Edit from './edit.vue'

export default {
  name: 'LkyApplyAdminPass',
  components: {
    Edit
  },
  data () {
    return {
      editLkyApplyAdminPass: null,
      formLkyApplyAdminPass: {
        id: '',
        USER_NAME: '',
        file_name: '',
        name1: '',
        name2: '',
        name3: '',
        creation_time: '',
        pass_time: '',
		remark_info:'',
      },
      columns: [
        { key: 'USER_NAME', title: '学生', sortable: true },
        { key: 'file_name', title: '表名', sortable: true },
        { key: 'name1', title: '班级', sortable: true },
        { key: 'name2', title: '专业', sortable: true },
        { key: 'name3', title: '学院', sortable: true },
        { key: 'creation_time', title: '申请时间', sortable: true },
        { key: 'pass_time', title: '通过时间', sortable: true },
        {
          title: '操作',
          key: 'action',
          width: 250,
          align: 'center',
          render: (h, params) => {
            return h('div', [
              h(
                'Button',
                {
                  props: {
                    type: 'primary',
                    size: 'small'
                  },
                  style: {
                    marginRight: '5px'
                  },
                  on: {
                    click: () => {
                      this.editLkyApplyAdminPass = params.row
                      this.handleOpenPage('edit')
                    }
                  }
                },
                '查看'
              )
            ])
          }
        }
      ],
      tableData: [],
      total: 0,
      current: 1,
      pageSize: 10,
      isOpenAddPage: false,
      isOpenEditPage: false,
      selection: [],
	  // 创建容器
	  coid: '',
	  mid: '',
	  cid: '',
	  collegeList: [],
	  majorList: [],
	  classList: []
    }
  },
  methods: {
    onOpenChangeCollege() {
    	queryAll().then(res => {
    		this.collegeList = res.data
    	})
    },
    onOpenChangeMajor(coid) {
    	this.cid = ''
    	this.mid = ''
    	queryAllM({
    		'coid': this.coid
    	}).then(res => {
    		this.majorList = JSON.parse(JSON.stringify(res.data))
    	})
    },
    onOpenFindClassByMid(mid) {
    	
    	queryFindClassByMid({
    		'mid': this.mid
    	}).then(res => {
    		this.classList = JSON.parse(JSON.stringify(res.data))
    	})
    },
    handleSubmit (name) {
      // 查询按钮事件
      this.getLkyClassList(this.current, this.pageSize)
      this.$Message.success('Success!')
    },	
    handleReset (name) {
      // 重置按钮事件
      this.coid = ''
      this.formLkyApplyAdminPass.mid = ''
      this.$refs[name].resetFields()
    },
    handleOpenPage (name) {
      // 打开页面事件(添加页,编辑页...)
      // === 是地址相同
      // == 是值相同
      if (name == 'add') this.isOpenAddPage = true
      else if (name == 'edit') {
        this.isOpenEditPage = true
      }
    },
    addLkyClass (row) {
      this.tableData.push(row)
      this.getLkyClassList(this.current, this.pageSize)
    },
    updateLkyClass (row) {
      this.$set(this.tableData, row._index, row)
    },
 
    getLkyClassList (current, pageSize, paras) {
      let para = { pageNumber: current, pageSize: pageSize }
      if (paras) Object.assign(para, paras)
	  Object.assign(para, {
	  	coid: this.coid,
	  	mid: this.mid,
	  	cid: this.cid,
	  	
	  })
      list(this.handleRequestParams(para)).then(res => {
        console.table(res.list)
        this.tableData = res.list
        this.current = parseInt(res.pageNumber)
        this.pageSize = parseInt(res.pageSize)
        this.total = parseInt(res.totalRow)
      })
    },
    
    handleRequestParams (para) {
      Object.assign(para, createFormObj(this.formLkyApplyAdminPass, 'lkyClass'))
      // 后端还需要coid 数据，coid不属于 lkyClass
      Object.assign(para, { coid: this.coid })
      console.log('para')
      console.log(para)
      return para
    },
    exportExcel () {
      this.$refs.tableLkyClass.exportCsv({
        filename: `table-${new Date().valueOf()}.csv`
      })
    },
    changePage (pageNumber) {
      this.getLkyClassList(pageNumber, this.pageSize)
    },
    changePageSize (pageSize) {
      this.getLkyClassList(this.current, pageSize)
    },
    remove (index) {
      this.data6.splice(index, 1)
    },
    onSelectionChange (selection) {
      this.selection = selection
    },
    onSortChange (obj) {
      if (obj.order === 'normal') {
        this.getLkyClassList(1, this.pageSize)
      } else {
        this.getLkyClassList(1, this.pageSize, {
          field: obj.key,
          order: obj.order
        })
      }
    }
  },
  mounted () {
    this.getLkyClassList(this.current, this.pageSize)
  }
}
</script>

<style>
</style>

